package com.jbh.checknetdemo;

import static com.jbh.netlibrary.m.NetManager.TOAST;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jbh.netlibrary.i.NetStateListener;
import com.jbh.netlibrary.u.InitConfig;
import com.jbh.netlibrary.m.NetManager;
import com.jbh.netlibrary.u.NetStateUtils;

public class MainActivity extends AppCompatActivity {

    TextView tvNetMsg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvNetMsg = findViewById(R.id.tvNetMsg);
        InitConfig initConfig = new InitConfig();
        initConfig.setNetStateListener(new NetStateListener() {
            @Override
            public void onRefresh() {
                TOAST(MainActivity.this,"开始刷新");
            }
        });
        NetManager.getInstance().setConfig(initConfig);
        tvNetMsg.setText(NetStateUtils.isHaveNet(MainActivity.this) ? "网络正常" : "网络不可用");
        findViewById(R.id.tvNetMsg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NetManager.getInstance().refresh(MainActivity.this);
            }
        });
    }


    @Override
    protected void onResume() {
        super.onResume();
        NetManager.getInstance().onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        NetManager.getInstance().onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        NetManager.getInstance().onDestroy();
    }
}